package com.winit.flow.service;

import com.winit.common.base.bean.ExecuteResult;
import com.winit.flow.manager.FlowManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FlowServiceImpl implements IFlowService {

    private static Logger log = LoggerFactory.getLogger(FlowServiceImpl.class);

    @Autowired
    private FlowManager flowManager;

    @Override
    public ExecuteResult reqSubmit(String reqId, String version) {
        return this.flowManager.reqSubmit(reqId, version);
    }

    @Override
    public ExecuteResult operateForReqOnline(String reqId) {

        ExecuteResult executeResult = null;
        try {
            executeResult = this.flowManager.operateForReqOnline(reqId);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            executeResult.toError(e.getMessage());
            return executeResult;
        }
        if (!executeResult.success()) {
            return executeResult;
        }
        return executeResult;
    }
}
